1 package activity;
2
3 import java.lang.*;
4 import javax.swing.*;
5 import java.awt.*;
6 import javax.swing.border.*;
7 import java.awt.
event.*;
8 import java.sql.*;
9 import attr.*;

10
11 public
class SignupActivity extends JFrame implements ActionListener {
12     
private JPanel panel;
13     
private JButton buttonExit, buttonSubmit, buttonBack;
14     
private JLabel title, header, usernameLabel, passwordLabel, nameLabel, phoneLabel, addressLabel;
15     
private JTextField usernameTF, nameTF, phoneTF1, phoneTF2, addressTF;
16     
private JPasswordField passwordF;
17     
public SignupActivity() {
18         super(
"Sign up");
19         
20         
this.setSize(Theme.GUI_WIDTH, Theme.GUI_HEIGHT);
21         
this.setResizable(false);
22         
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
23         
this.setLocationRelativeTo(null);
24         
25         panel =
new JPanel();
26         panel.setLayout(
null);
27         panel.setBackground(Theme.BACKGROUND_PANEL);
28         
29         title =
new JLabel("Sign up");
30         title.setBounds(
30, 40, 200,75);
31         title.setOpaque(
true);
32         title.setBorder(
new EmptyBorder(0,20,0,0));
33         title.setFont(Theme.FONT_TITLE);
34         title.setForeground(Theme.COLOR_TITLE);
35         panel.
add(title);
36         
37         buttonExit =
new JButton("Exit");
38         buttonExit.setBounds(Theme.GUI_WIDTH-
140, 40, Theme.BUTTON_PRIMARY_WIDTH,30);
39         buttonExit.setFont(Theme.FONT_BUTTON);
40         buttonExit.setBackground(Color.WHITE);
41         buttonExit.setForeground(Theme.COLOR_TITLE);
42         buttonExit.addActionListener(
this);
43         panel.
add(buttonExit);
44         
45         buttonBack =
new JButton("Back");
46         buttonBack.setBounds(Theme.GUI_WIDTH-
140, 80, Theme.BUTTON_PRIMARY_WIDTH,30);
47         buttonBack.setFont(Theme.FONT_BUTTON);
48         buttonBack.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
49         buttonBack.setForeground(Theme.COLOR_BUTTON_PRIMARY);
50         buttonBack.addActionListener(
this);
51         panel.
add(buttonBack);
52         
53         usernameLabel =
new JLabel("User ID: ");
54         usernameLabel.setBounds(
60, 140, 140, 30);
55         usernameLabel.setFont(Theme.FONT_REGULAR);
56         panel.
add(usernameLabel);
57         
58         passwordLabel =
new JLabel("Password: ");
59         passwordLabel.setBounds(
60, 190, 140, 30);
60         passwordLabel.setFont(Theme.FONT_REGULAR);
61         panel.
add(passwordLabel);
62         
63         nameLabel =
new JLabel("Name: ");
64         nameLabel.setBounds(
60, 240, 140, 30);
65         nameLabel.setFont(Theme.FONT_REGULAR);
66         panel.
add(nameLabel);
67         
68         phoneLabel =
new JLabel("Phone No: ");
69         phoneLabel.setBounds(
60, 290, 140, 30);
70         phoneLabel.setFont(Theme.FONT_REGULAR);
71         panel.
add(phoneLabel);
72         
73         addressLabel =
new JLabel("Address: ");
74         addressLabel.setBounds(
60, 340, 140, 30);
75         addressLabel.setFont(Theme.FONT_REGULAR);
76         panel.
add(addressLabel);
77         
78         usernameTF =
new JTextField();
79         usernameTF.setBounds(
180, 140, 220, 30);
80         usernameTF.setFont(Theme.FONT_INPUT);
81         panel.
add(usernameTF);
82         
83         passwordF =
new JPasswordField();
84         passwordF.setBounds(
180, 190, 220, 30);
85         passwordF.setFont(Theme.FONT_INPUT);
86         panel.
add(passwordF);
87         
88         nameTF =
new JTextField();
89         nameTF.setBounds(
180, 240, 220, 30);
90         nameTF.setFont(Theme.FONT_INPUT);
91         panel.
add(nameTF);
92         
93         phoneTF1 =
new JTextField("+880");
94         phoneTF1.setBounds(
180, 290, 40, 30);
95         phoneTF1.setForeground(Theme.COLOR_BUTTON_PRIMARY);
96         phoneTF1.setEnabled(
false);
97         phoneTF1.setFont(Theme.FONT_INPUT);
98         phoneTF1.setDisabledTextColor(Color.BLACK);
99         panel.
add(phoneTF1);
100         
101         phoneTF2 =
new JTextField();
102         phoneTF2.setBounds(
220, 290, 180, 30);
103         phoneTF2.setFont(Theme.FONT_INPUT);
104         panel.
add(phoneTF2);
105         
106         addressTF =
new JTextField();
107         addressTF.setBounds(
180, 340, 220, 30);
108         addressTF.setFont(Theme.FONT_INPUT);
109         panel.
add(addressTF);
110         
111         buttonSubmit =
new JButton("Submit");
112         buttonSubmit.setBounds(
70, 400, 300, 35);
113         buttonSubmit.setFont(Theme.FONT_BUTTON);
114         buttonSubmit.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
115         buttonSubmit.setForeground(Theme.COLOR_BUTTON_PRIMARY);
116         buttonSubmit.addActionListener(
this);
117         panel.
add(buttonSubmit);
118         
119         header =
new JLabel();
120         header.setBackground(Theme.BACKGROUND_HEADER);
121         header.setOpaque(
true);
122         header.setBounds(
0, 0, Theme.GUI_WIDTH, 75);
123         panel.
add(header);
124         
125         
this.add(panel);
126     }
127     
128     
public void actionPerformed(ActionEvent ae) {
129         
if (ae.getSource().equals(buttonExit))
130             System.exit(
0);
131         
else if (ae.getSource().equals(buttonBack)) {
132             
this.setVisible(false);
133             
new LoginActivity().setVisible(true);
134         }
135         
else if (ae.getSource().equals(buttonSubmit)) {
136             
try {
137                 Customer c =
new Customer(usernameTF.getText().trim());
138                 c.setPassword(passwordF.getText());
139                 c.setCustomerName(nameTF.getText());
140                 c.setPhoneNumber(Integer.parseInt(phoneTF2.getText()));
141                 c.setAddress(addressTF.getText());
142                 c.createCustomer(
this);
143             }
144             
catch (NumberFormatException e) {
145                 JOptionPane.showMessageDialog(
this,"Enter phone no correctly!");
146             }
147             
catch (IllegalArgumentException e) {
148                 JOptionPane.showMessageDialog(
this,e.getMessage());
149             }
150         }
151         
else {}
152     }
153 }


Gõ tìm kiếm nhanh...